//
//  BaseTabBarController.m
//  news
//
//  Created by lanou on 15/12/16.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "BaseTabBarController.h"
#import "HomePageTableViewController.h"
#import "RadioViewController.h"
#import "VideoTableViewController.h"
@interface BaseTabBarController ()

@property (nonatomic, strong) UITapGestureRecognizer *tap;

@property (nonatomic, strong) UIView *tapView;

@end

@implementation BaseTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tabBar.tintColor = [UIColor redColor];
    self.tabBar.barTintColor = [UIColor groupTableViewBackgroundColor];
    
    
    HomePageTableViewController *homePageTVC = [[HomePageTableViewController alloc] initWithStyle:(UITableViewStylePlain)];
    
    RadioViewController *radioVC = [[RadioViewController alloc] init];
    
    VideoTableViewController *videoTVC = [[VideoTableViewController alloc]initWithStyle:UITableViewStylePlain];
    [self addChildViewController:videoTVC title:@"视听" image:@"video1.png"];
    
    [self addChildViewController:homePageTVC title:@"首页" image:@"news.png"];
    
    [self addChildViewController:radioVC title:@"电台" image:@"radio.png"];
    
    UIButton *button = [UIButton buttonWithType:(UIButtonTypeSystem)];
    button.frame = CGRectMake(10, 30, 60, 20);
    [button setTitle:@"侧边栏" forState:(UIControlStateNormal)];
    [button addTarget:self action:@selector(cebianlan) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    [self.view addSubview:button];
    
    // Do any additional setup after loading the view.
}

static bool isSidebar = NO;

- (UITapGestureRecognizer *)tap
{
    if (!_tap) {
        _tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cebianlan)];
    }
    return _tap;
}

- (void)cebianlan
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"isSidebar" object:nil];
    if (isSidebar) {
        
        [self.tapView removeFromSuperview];
        isSidebar = NO;
        
    } else {
        
        self.tapView = [[UIView alloc] initWithFrame:self.view.bounds];
        self.tapView.backgroundColor = [UIColor clearColor];
        [self.tapView addGestureRecognizer:self.tap];
        [self.view addSubview:self.tapView];
        isSidebar = YES;
    }
}

- (void)addChildViewController:(UIViewController *)childController title:(NSString *)title image:(NSString *)image
{
    UINavigationController *childVC = [[UINavigationController alloc] initWithRootViewController:childController];
    childVC.tabBarItem.title = title;
    childVC.tabBarItem.image = [UIImage imageNamed:image];
    childVC.navigationBar.barTintColor = [UIColor whiteColor];
    [self addChildViewController:childVC];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
